//
//  UIButton+Extension.m
//  服装
//
//  Created by mac on 16/4/10.
//  Copyright © 2016年 安安. All rights reserved.
//

#import "UIButton+Extension.h"

@implementation UIButton (Extension)
+ (UIButton *) leftButtonWithFrame:(CGRect)frame backGroundCorlor:(UIColor *)buttonBackGroungCorlor title:(NSString *)title titleForState:(UIControlState)titleForStateState enable:(BOOL)enabled titleCorlor:(UIColor *)titleCorlor titleCorlorForState:(UIControlState)titleCorlorForState titleLableFont:(CGFloat) font {
    
    
    UIButton *button = [[UIButton alloc] initWithFrame:frame];
    [button setBackgroundColor:buttonBackGroungCorlor];
    [button setTitle:title forState:titleForStateState];
    button.enabled = enabled;
    [button setTitleColor:titleCorlor forState:titleCorlorForState];
    button.titleLabel.font = [UIFont systemFontOfSize:font];
    
    
    return button;
    
}
+ (UIButton *) rightButtonWithFrame:(CGRect)frame backGroundCorlor:(UIColor *)buttonBackGroungCorlor title:(NSString *)title titleForState:(UIControlState)titleForStateState enable:(BOOL)enabled titleCorlor:(UIColor *)titleCorlor titleCorlorForState:(UIControlState)titleCorlorForState titleLableFont:(CGFloat) font {
    
    UIButton *button = [[UIButton alloc] initWithFrame:frame];
    [button setBackgroundColor:buttonBackGroungCorlor];
    [button setTitle:title forState:titleForStateState];
    button.enabled = enabled;
    [button setTitleColor:titleCorlor forState:titleCorlorForState];
    button.titleLabel.font = [UIFont systemFontOfSize:font];
    
    
    
    
    return button;
    
}
+ (UIButton *) buttonWithFrame:(CGRect)frame title:(NSString *)title titleForState:(UIControlState)titleForStateState  titleCorlor:(UIColor *)titleCorlor titleCorlorForState:(UIControlState) titleCorlorForState {
    UIButton *button = [[UIButton alloc] initWithFrame:frame];
    [button setTitle:title forState:titleForStateState];
    [button setTitleColor:titleCorlor forState:titleCorlorForState];
   
    return button;
}

+ (UIButton *) buttonWithFrame:(CGRect)frame image:(NSString *)image imageForState:(UIControlState)imageForStateState
{
    UIButton *button = [[UIButton alloc] initWithFrame:frame];
    [button setImage:[UIImage imageNamed:image] forState:imageForStateState];
    return button;
}

- (void)centerImageAndTitle:(float)spacing
{
    // get the size of the elements here for readability
    CGSize imageSize = self.imageView.frame.size;
    CGSize titleSize = self.titleLabel.frame.size;
    
    // get the height they will take up as a unit
    CGFloat totalHeight = (imageSize.height + titleSize.height + spacing);
    
    // raise the image and push it right to center it
    self.imageEdgeInsets = UIEdgeInsetsMake(
                                               - (totalHeight - imageSize.height), 0.0, 0.0, - titleSize.width);
    
    // lower the text and push it left to center it
    self.titleEdgeInsets = UIEdgeInsetsMake(
                                               0.0, - imageSize.width, - (totalHeight - titleSize.height), 0.0);
}

- (void)centerImageAndTitle
{
    const int DEFAULT_SPACING = 6.0f;
    [self centerImageAndTitle:DEFAULT_SPACING];
}

@end
